package com.gitee.zw.irmp.report.rest;

import com.gitee.zw.irmp.report.service.IReportManageService;
import com.ibm.risk.irmp.common.auth.AuthUtils;
import com.gitee.zw.irmp.report.vo.ReportItemVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v2/manage/reports")
public class ReportManageController {

    @Autowired
    IReportManageService reportDataService;

    /**
     * 读取报表列表
     */
    @GetMapping(value = "/categories/{category}")
    public List<ReportItemVo> reportList(@PathVariable String category) {
        if (StringUtils.isEmpty(category)) {
            throw new RuntimeException("请指定报表大类");
        }

        if ("ALL".equals(category)) {
            category = null;
        }

        List<ReportItemVo> reportList = reportDataService.getReportListTree(category, "T",
                AuthUtils.getLoginUsername());
        return reportList;
    }

}
